package com.xj.bean.aop;

import com.alibaba.fastjson.JSON;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;

/**
 * @Aspect 高速当前类是切面类
 */
@Aspect
public class LogAspects {

    @Pointcut("execution(public int com.xj.bean.aop.MathCalculator.*(..))")
    public void pointCut() {

    }

    @Before("pointCut()")
    public void logStart(JoinPoint joinPoint) {
        Object[] args = joinPoint.getArgs();
        System.out.println("" + joinPoint.getSignature().getName() + "运行。。。@Before参数是{" + JSON.toJSONString(args) +"}");
    }
    @After("pointCut()")
    public void logEnd(JoinPoint joinPoint) {
        System.out.println("" + joinPoint.getSignature().getName() + "运行结束。。。");
    }
    @AfterReturning(value = "pointCut()", returning = "result")
    public void logReturn(JoinPoint joinPoint, Object result) {
        System.out.println("" + joinPoint.getSignature().getName() + "运行正常返回。。。运行结果是{" + JSON.toJSONString(result) + "}");
    }
    @AfterThrowing(value = "pointCut()", throwing = "exception")
    public void logException(JoinPoint joinPoint, Exception exception) {
        System.out.println("" + joinPoint.getSignature().getName() + "运行异常。。。异常信息是{" + exception.getMessage() + "}");
    }
//    public void logStart() {
//        System.out.println("除法运行。。。参数是{}");
//    }
}
